package com.pp.ent.util.asynctask;

/**
 * Created by dengqu on 2017/3/2.
 */

import android.os.HandlerThread;
import android.os.Looper;

import com.pp.ent.base.common.SafeHandlerDispatch;

public final class AsyncTask
{
    private Looper mTaskLooper;
    private SafeHandlerDispatch mTaskHandler;
    private HandlerThread mThread;

    public AsyncTask()
    {
        this("AsyncTask");
    }

    public AsyncTask(String name)
    {
        this.mThread = new HandlerThread(name);
        this.mThread.start();

        this.mTaskLooper = this.mThread.getLooper();
        this.mTaskHandler = new SafeHandlerDispatch(this.mTaskLooper);
    }

    public void execute(Runnable command)
    {
        this.mTaskHandler.removeCallbacks(command);
        this.mTaskHandler.post(command);
    }
}